package com.csit.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="T_Customer")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Customer implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer customerID;
	
	@Column(length=50,unique=true)
	private String customerCode;
	
	@Column(length=100)
	private String customerName;
	
	@Column(length=4)
	private String sex;
	
	@Temporal(TemporalType.DATE)
	private Date birthday;
	
	@Column(length=1000)
	private String character;
	
	@Column(length=255)
	private String company;
	
	@Column(length=100)
	private String roleName;
	
	@Column(length=50)
	private String telephone;
	
	@Column(length=255)
	private String address;
	
	@Column(length=2000)
	private String note;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="customerTypeID")
	private DataDictionary customerType;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="customerSourceID")
	private DataDictionary customerSource;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="shopID")
	private DataDictionary shop;
	
	public Integer getCustomerID() {
		return customerID;
	}

	public void setCustomerID(Integer customerID) {
		this.customerID = customerID;
	}

	public String getCustomerCode() {
		return customerCode;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getCharacter() {
		return character;
	}

	public void setCharacter(String character) {
		this.character = character;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public DataDictionary getCustomerType() {
		return customerType;
	}

	public void setCustomerType(DataDictionary customerType) {
		this.customerType = customerType;
	}

	public DataDictionary getCustomerSource() {
		return customerSource;
	}

	public void setCustomerSource(DataDictionary customerSource) {
		this.customerSource = customerSource;
	}

	public DataDictionary getShop() {
		return shop;
	}

	public void setShop(DataDictionary shop) {
		this.shop = shop;
	}
	@Transient
	public void setCustomerTypeID(Integer customerTypeID){
		if(customerType==null){
			customerType = new DataDictionary();
		}
		customerType.setDataDictionaryID(customerTypeID);
	}
	@Transient
	public Integer getCustomerTypeID(){
		if(customerType==null){
			return null;
		}
		return customerType.getDataDictionaryID();
	}
	@Transient
	public String getCustomerTypeName(){
		if(customerType==null){
			return null;
		}
		return customerType.getDataDictionaryName();
	}
	@Transient
	public void setCustomerSourceID(Integer customerSourceID){
		if(customerSource==null){
			customerSource = new DataDictionary();
		}
		customerSource.setDataDictionaryID(customerSourceID);
	}
	@Transient
	public Integer getCustomerSourceID(){
		if(customerSource==null){
			return null;
		}
		return customerSource.getDataDictionaryID();
	}
	@Transient
	public String getCustomerSourceName(){
		if(customerSource==null){
			return null;
		}
		return customerSource.getDataDictionaryName();
	}
}
